package com.jf.hotelreservation.demos.service.impl;

import com.alibaba.fastjson2.JSON;
import com.jf.hotelreservation.demos.bean.Areas;
import com.jf.hotelreservation.demos.bean.Cities;
import com.jf.hotelreservation.demos.bean.Province;
import com.jf.hotelreservation.demos.mapper.PCDMapper;
import com.jf.hotelreservation.demos.service.PCDService;
import com.jf.hotelreservation.demos.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class PCDServiceImpl implements PCDService {

    @Autowired
    private PCDMapper pcdMapper;
    @Override
    public String getProvince() {
        List<Province> province = pcdMapper.getProvince();
        if (province.isEmpty()){
            return JSON.toJSONString(R.error("查询失败"));
        }else {
            return JSON.toJSONString(R.success(province));
        }

    }

    @Override
    public String getCity(Integer id) {
        List<Cities> city = pcdMapper.getCity(id);
        if (city.isEmpty()){
            return JSON.toJSONString(R.error("查询失败"));
        }else {
            return JSON.toJSONString(R.success(city));
        }
    }

    @Override
    public String getArea(Integer id) {
        List<Areas> area = pcdMapper.getArea(id);
        if (area.isEmpty()){
            return JSON.toJSONString(R.error("查询失败"));
        }else {
            return JSON.toJSONString(R.success(area));
        }
    }
}
